package v1

import (
    "authserver/global"
    "authserver/global/response"
    "authserver/model"
    "authserver/service"
    "github.com/gin-gonic/gin"
)

// GetMbtiTopics
// @Summary 查询所有的问题
// @Router /api/mbti/topics [post]
func GetMbtiTopics(c *gin.Context) {

    key := c.Query("key")

    if key == "" {
        global.GVA_LOG.Error("请输入注册码....")
        response.FailWithMessage("请输入注册码", c)
        return
    }

    topics := service.GetMbtiQuestionTopics()
    response.OkWithData(topics,c)
}

// AddMbtiResult
// @Summary 查询所有的问题
// @Router /api/mbti/addResult [post]
func AddMbtiResult(c *gin.Context) {

    var result model.MbtiResult
    c.ShouldBindJSON(&result)

    if result.Username == "" {
        global.GVA_LOG.Error("请输入注册码....")
        response.FailWithMessage("请输入注册码", c)
        return
    }

    err := service.AddMbtiResult(result)
    if err!=nil{
        response.FailWithMessage("提交失败",c)

    }else{
        response.OkWithMessage("",c)
    }
}

// GetMbtiAnswer
// @Summary 查询所有的问题
// @Router /api/mbti/getAnalync [post]
func GetMbtiAnswer(c *gin.Context) {

    var result model.MbtiResult
    c.ShouldBindJSON(&result)

    if result.MbtiKind == "" {
        global.GVA_LOG.Error("参数有误")
        response.FailWithMessage("参数有误", c)
        return
    }

    err,info := service.GetMbtiAnswer(result.MbtiKind)
    if err!=nil{
        response.FailWithMessage("提交失败",c)
    }else{
        response.OkWithData(info,c)
    }
}

